Simpson's rule

In numerical analysis, Simpson's rule is a method for numerical integration, the numerical approximation of definite integrals. Specifically, it is the following approximation:

 \int_{a}^{b} f(x) \, dx \approx \frac{b-a}{6}\left[f(a) %2B 4f\left(\frac{a%2Bb}{2}\right)%2Bf(b)\right].

Simpson's rule also corresponds to the 3-point Newton-Cotes quadrature rule.

The method is credited to the mathematician Thomas Simpson (1710–1761) of Leicestershire, England. Kepler used similar formulas over 100 years prior and in German the method is sometimes called Keplersche Fassregel for this reason.

Simpson's rule is a staple of scientific data analysis and engineering. It is widely used, for example, by Naval architects to calculate the capacity of a ship or lifeboat.[1]

Contents

Derivation

Simpson's rule can be derived in various ways.

Quadratic interpolation

One derivation replaces the integrand f(x) by the quadratic polynomial P(x) which takes the same values as f(x) at the end points a and b and the midpoint m = (a + b) / 2. One can use Lagrange polynomial interpolation to find an expression for this polynomial,

 P(x) = f(a) \frac{(x-m)(x-b)}{(a-m)(a-b)} %2B f(m) \frac{(x-a)(x-b)}{(m-a)(m-b)} %2B f(b) \frac{(x-a)(x-m)}{(b-a)(b-m)}.

An easy (albeit tedious) calculation shows that

 \int_{a}^{b} P(x) \, dx =\frac{b-a}{6}\left[f(a) %2B 4f\left(\frac{a%2Bb}{2}\right)%2Bf(b)\right]. [2]

This calculation can be carried out more easily if one first observes that (by scaling) there is no loss of generality in assuming that a=-1 and b=1.

Averaging the midpoint and the trapezoidal rules

Another derivation constructs Simpson's rule from two simpler approximations: the midpoint rule

 M = (b-a) f \left( \frac{a%2Bb}{2} \right)

and the trapezoidal rule

 T = \tfrac12 (b-a) (f(a)%2Bf(b)).

The errors in these approximations are

 -\tfrac1{ 24} (b-a)^3 f''(a) %2B O((b-a)^4) \quad\text{and}\quad \tfrac1{12} (b-a)^3 f''(a) %2B O((b-a)^4),

respectively. It follows that the leading error term vanishes if we take the weighted average

 \frac{2M%2BT}{3}.

This weighted average is exactly Simpson's rule.

Using another approximation (for example, the trapezoidal rule with twice as many points), it is possible to take a suitable weighted average and eliminate another error term. This is Romberg's method.

Undetermined coefficients

The third derivation starts from the ansatz

 \frac{1}{b-a} \int_{a}^{b} f(x) \, dx \approx \alpha f(a) %2B \beta f\left(\frac{a%2Bb}{2}\right) %2B \gamma f(b).

The coefficients α, β and γ can be fixed by requiring that this approximation be exact for all quadratic polynomials. This yields Simpson's rule.

Error

The error in approximating an integral by Simpson's rule is

 \frac{1}{90} \left(\frac{b-a}{2}\right)^5 \left|f^{(4)}(\xi)\right|,

where \xi is some number between a and b.[3]

The error is asymptotically proportional to (b-a)^5. However, the above derivations suggest an error proportional to (b-a)^4. Simpson's rule gains an extra order because the points at which the integrand is evaluated are distributed symmetrically in the interval [a, b].

Since the error term is proportional to the fourth derivative of f at \xi, this shows that Simpson's rule provides exact results for any polynomial f of degree three or less, since the fourth derivative of such a polynomial is zero at all points.

Composite Simpson's rule

If the interval of integration [a, b] is in some sense "small", then Simpson's rule will provide an adequate approximation to the exact integral. By small, what we really mean is that the function being integrated is relatively smooth over the interval [a, b]. For such a function, a smooth quadratic interpolant like the one used in Simpson's rule will give good results.

However, it is often the case that the function we are trying to integrate is not smooth over the interval. Typically, this means that either the function is highly oscillatory, or it lacks derivatives at certain points. In these cases, Simpson's rule may give very poor results. One common way of handling this problem is by breaking up the interval [a, b] into a number of small subintervals. Simpson's rule is then applied to each subinterval, with the results being summed to produce an approximation for the integral over the entire interval. This sort of approach is termed the composite Simpson's rule.

Suppose that the interval [a, b] is split up in n subintervals, with n an even number. Then, the composite Simpson's rule is given by

\int_a^b f(x) \, dx\approx 
\frac{h}{3}\bigg[f(x_0)%2B2\sum_{j=1}^{n/2-1}f(x_{2j})%2B
4\sum_{j=1}^{n/2}f(x_{2j-1})%2Bf(x_n)
\bigg],

where x_j=a%2Bjh for j=0, 1, ..., n-1, n with h=(b-a)/n; in particular, x_0=a and x_n=b. The above formula can also be written as

\int_a^b f(x) \, dx\approx
\frac{h}{3}\bigg[f(x_0)%2B4f(x_1)%2B2f(x_2)%2B4f(x_3)%2B2f(x_4)%2B\cdots%2B4f(x_{n-1})%2Bf(x_n)\bigg].

The error committed by the composite Simpson's rule is bounded (in absolute value) by

\frac{h^4}{180}(b-a) \max_{\xi\in[a,b]} |f^{(4)}(\xi)|,

where h is the "step length", given by h=(b-a)/n.[4]

This formulation splits the interval [a,b] in subintervals of equal length. In practice, it is often advantageous to use subintervals of different lengths, and concentrate the efforts on the places where the integrand is less well-behaved. This leads to the adaptive Simpson's method.

Alternative extended Simpson's rule

This is another formulation of a composite Simpson's rule: instead of applying Simpson's rule to disjoint segments of the integral to be approximated, Simpson's rule is applied to overlapping segments, yielding:[5]


\int_a^b f(x) \, dx\approx
\frac{h}{48}\bigg[17f(x_0)%2B59f(x_1)%2B43f(x_2)%2B49f(x_3)%2B48 \sum_{i=4}^{n-4} f(x_i)%2B49f(x_{n-3})%2B43f(x_{n-2})%2B59f(x_{n-1})%2B17f(x_n)\bigg].

Simpson's 3/8 rule

Simpson's 3/8 rule is another method for numerical integration proposed by Thomas Simpson. It is based upon a cubic interpolation rather than a quadratic interpolation. Simpson's 3/8 rule is as follows:

 \int_{a}^{b} f(x) \, dx \approx \frac{3h}{8}\left[f(a) %2B 3f\left(\frac{2a%2Bb}{3}\right) %2B 3f\left(\frac{a%2B2b}{3}\right) %2B f(b)\right] 
= \frac{(b-a)}{8}\left[f(a) %2B 3f\left(\frac{2a%2Bb}{3}\right) %2B 3f\left(\frac{a%2B2b}{3}\right) %2B f(b)\right].

The error of this method is:

 \left|\frac{(b-a)^5}{6480} f^{(4)}(\xi)\right|,

where \xi is some number between a and b. Thus, the 3/8 rule is about twice as accurate as the standard method, but it uses one more function value. A composite 3/8 rule also exists, similarly as above.[6]

Sample implementation

An implementation of the composite Simpson's rule in pylab:

def simpson(f, a, b, n):
    """f=function, a=initial value, b=end value, n=number of double intervals of size 2h"""
 
    n *= 2
    h = (b - a) / n;
    S = f(a)
 
    for i in range(1, n, 2):
        x = a + h * i
        S += 4 * f(x)
 
    for i in range(2, n-1, 2):
        x = a + h * i
        S += 2 * f(x)
 
    S += f(b)
    F = h * S / 3
 
    return F

See also

Notes

  1. ^ McCall Pate (1918). The naval artificer's manual: (The naval artificer's handbook revised) text, questions and general information for deck. United States. Bureau of Reconstruction and Repair. p. 198. http://books.google.com/books?id=bQc9AAAAYAAJ&pg=PA198. 
  2. ^ Atkinson, p. 256; Süli and Mayers, §7.2
  3. ^ Atkinson, equation (5.1.15); Süli and Mayers, Theorem 7.2
  4. ^ Atkinson, pp. 257+258; Süli and Mayers, §7.5
  5. ^ Press (1989), p. 122
  6. ^ Matthews (2004)

References

External links

This article incorporates material from Code for Simpson's rule on PlanetMath, which is licensed under the Creative Commons Attribution/Share-Alike License.